package com.sun.service;

import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.sun.dubbo.service.DubboService;
import com.sun.pojo.Menu;
import com.sun.pojo.MenuCustom;



@Service("WebmanageService")
public class WebmanageServiceImpl implements WebmanageService{

	@Reference
	private DubboService dubboService;
	
	private static final Logger LOGGER = LoggerFactory.getLogger(WebmanageService.class);
	
	@Override
	public List<MenuCustom> listMenuTree() {
		return dubboService.listMenu();
	}

	@Override
	public Integer insertMenu(Menu menu) {
		Integer id = null;
		try {
			id = dubboService.saveMenu(menu);
		} catch (Exception e) {
			LOGGER.info("WebmanageService addMenu errinfo==="+e.getMessage());
			return null;
		}
		return id;
	}

	@Override
	public boolean updateMenu(Menu menu) {
		boolean flag = false;
		try {
			Menu old = dubboService.loadMenu(menu.getId());
			BeanUtils.copyProperties(old,menu,true);
			flag = dubboService.updateMenu(old);
		} catch (Exception e) {
			LOGGER.info("WebmanageService updateMenu errinfo==="+e.getMessage());
			return false;
		}
		if(flag){
			return true;
		}
		return false;
	}

	@Override
	public boolean delMenu(Integer id) {
		boolean flag = false;
		try {
			 flag = dubboService.delMenu(id);
		} catch (Exception e) {
			LOGGER.info("WebmanageService delMenu errinfo==="+e.getMessage());
			return false;
		}
		if(flag){
			return true;
		}
		return false;
	}

}
